package cn.wolfcode.business.controller;

import cn.wolfcode.business.domain.BusStatementItem;
import cn.wolfcode.business.domain.vo.StatementItemVo;
import cn.wolfcode.business.service.IBusStatementItemService;
import cn.wolfcode.common.core.controller.BaseController;
import cn.wolfcode.common.core.domain.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 结算单明细Controller
 * 
 * @author wolfcode
 * @date 2025-08-22
 */
@RestController
@RequestMapping("/business/item")
public class BusStatementItemController extends BaseController
{
    @Autowired
    private IBusStatementItemService busStatementItemService;

    /**
     * 根据结算单ID，查询结算单明细列表
     */
    @GetMapping
    public AjaxResult list(Long statementId){
        BusStatementItem item = new BusStatementItem();
        item.setStatementId(statementId);
        List<BusStatementItem> busStatementItems = busStatementItemService.selectBusStatementItemList(item);
        return AjaxResult.success(busStatementItems);
    }
    /**
     * 保存功能：方式一：正常定义 VO 方式接受参数
     */
    @PostMapping()
    public AjaxResult saveItem(@RequestBody StatementItemVo vo)
    {
        return toAjax(busStatementItemService.saveItem(vo));
    }
   /**
     * 保存功能：方式二：接收额外参数
     */
    /*@PostMapping()
    public AjaxResult saveItem(@RequestBody List<BusStatementItem> statementItemList)
    {
        // 接受参数
        statementItemList.forEach(System.out::println);
        // 将最后一位提取出来
        BusStatementItem remove = statementItemList.remove(statementItemList.size() - 1);
        System.out.println("截取后的 statementItemList");
        statementItemList.forEach(System.out::println);
        BigDecimal discountAmount = remove.getItemPrice();
        System.out.println("折扣价格为：" + discountAmount );
        return AjaxResult.success();
    }*/

    /**
     * 支付功能
     */
    @PatchMapping(value = "/{statementId}",headers = "cmd=pay")
    public AjaxResult pay(@PathVariable Long statementId){
        return toAjax(busStatementItemService.pay(statementId));
    }
}
